<?php

// Error if we don't have a Project ID and Crudset ID
//Incluce DB connect 
include_once "quickcrud_connect.php";
//include_once "commonctls.php";
include "CF_mysql_com.php";
include_once "CF_all_com.php";

if (!isset($_REQUEST['project_id']) OR !isset($_REQUEST['crudset_id']) ){
	print 'Please select or create a project first';
	exit;
}

function put_into_file($filename, $inserttext, $starttag, $endtag, $note){

print "Looking for $starttag";
	$infiletext = file_get_contents($filename);
	$startposition = 0;
	while($starttagpos = strpos($infiletext, $starttag, $startposition)){
		print "starting at $startposition found $starttag at $starttagpos <br>\n";
		$endtagpos = strpos($infiletext, $endtag, $starttagpos);
		print "Found endtag at $endtagpos <br>\n";

		//copy before into newstring
		$processedtext = substr($infiletext, 0, $starttagpos);

		//copy inserttext into newstring
		$processedtext .= $starttag;
		$processedtext .= "$note\n";
		$processedtext .= "$inserttext\n";

		//copy aftertext into newstring
		$processedtext .= substr($infiletext, $endtagpos);
		// next start position
		$startposition = $endtagpos + strlen($inserttext) + strlen($note) + strlen($endtag) + strlen($starttag) + 4;

		$result = file_put_contents($filename, $processedtext);
		$infiletext = file_get_contents($filename);
	}
	//	$starttagpos = strpos($infiletext, $starttag, $startposition);
}

$table = $_REQUEST['table'];
$project_id = $_REQUEST['project_id'];
$fieldspec = get_table_vars($table, $project_id);
echo "<html>\n<head>\n</head>\n<body>";
echo "<TEXTAREA NAME=\"comments\" COLS='80' ROWS='20'>$fieldspec</TEXTAREA>\n";
echo "</body></html>";

?>